"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025/6/16
"""
import requests
import time

headers = {
    "accept": "*/*",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "no-cache",
    "origin": "https://www.bilibili.com",
    "pragma": "no-cache",
    "priority": "u=1, i",
    "referer": "https://www.bilibili.com/",
    "sec-ch-ua": "\"Google Chrome\";v=\"137\", \"Chromium\";v=\"137\", \"Not/A)Brand\";v=\"24\"",
    "sec-ch-ua-mobile": "?0",
    "sec-ch-ua-platform": "\"Windows\"",
    "sec-fetch-dest": "empty",
    "sec-fetch-mode": "cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36"
}
cookies = {
    "buvid3": "B72B6032-AD4A-BA4D-6111-75914CF8048C71532infoc",
    "b_nut": "1741402071",
    "_uuid": "9C10DB10A9-57B6-8BE4-D962-B10937C4228B472410infoc",
    "buvid4": "02537230-1584-F34E-D3C9-49251C18379E72111-025030802-NQzWNe%2FA6Jmjrl%2BCkKWkKh4R3qzVxBznL4h6FB8%2BadH4INxVxHZOOlEZj%2FatpQwB",
    "enable_web_push": "DISABLE",
    "DedeUserID": "1413997530",
    "DedeUserID__ckMd5": "20d7209ba22e0c1b",
    "rpdid": "0zbfAHNOmh|6IjSM6rG|JVY|3w1TQKho",
    "header_theme_version": "CLOSE",
    "buvid_fp_plain": "undefined",
    "enable_feed_channel": "ENABLE",
    "historyviewmode": "list",
    "LIVE_BUVID": "AUTO4917418493316242",
    "PVID": "1",
    "CURRENT_QUALITY": "80",
    "fingerprint": "92adb8407f9f4534311200957ba14742",
    "buvid_fp": "92adb8407f9f4534311200957ba14742",
    "bili_ticket": "eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTAxNjQ3MjMsImlhdCI6MTc0OTkwNTQ2MywicGx0IjotMX0.15VMgzAKrhON2biMhNxWdVi3jSw7GpExpOnE_sJkpd4",
    "bili_ticket_expires": "1750164663",
    "bp_t_offset_1413997530": "1078552762897137664",
    "b_lsid": "F9BD2412_19776CA1F9E",
    "SESSDATA": "7a467469%2C1765596663%2C91020%2A61CjArK2Ptte4boOA6XNeFmQoYzN001sv6ND2w9EqJMAzW4EWmPFkP9puzsUFhmFXr5VgSVnR4ZTc1eGNFMXl5N2M2UEJ4MW9ZczNJWFhhSWtFRWsyX1ZTWVpqOENCZVo5OGhCZ3hPcWVVcXFhMjJNQ2tJRmI4OUpVekVMSVB6OUNXMVpnVEo5bnN3IIEC",
    "bili_jct": "4b3ccf379a30449708fb38a948308207",
    "sid": "78nzqsp0",
    "CURRENT_FNVAL": "4048",
    "home_feed_column": "4",
    "browser_resolution": "1306-967"
}
url = "https://api.bilibili.com/x/web-interface/wbi/index/top/feed/rcmd"
params = {
    "web_location": "1430650",
    "y_num": "3",
    "fresh_type": "4",
    "feed_version": "V8",
    "fresh_idx_1h": "1",
    "fetch_row": "4",
    "fresh_idx": "1",
    "brush": "1",
    "homepage_ver": "1",
    "ps": "12",
    "last_y_num": "4",
    "screen": "1306-967",
    "seo_info": "",
    "last_showlist": "av_114608669067892,av_114675576610741,av_114648883929050,av_114651769606765,ad_5614_114619104435545,av_114680223768388,av_114546593237195,av_n_114656400119731,av_n_114580349001209,av_n_114656282679126",
    "uniq_id": "1085589149691",
    "w_rid": "6ec7a498d315de667cd564c5f9e03c05",
    "wts": "1750047691"
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)

# print(response.text)
# print(response)
res = response.json()
item_list = res["data"]["item"]
# print(item_list)
for item in item_list:
    title = item["title"]
    image_url = item["owner"]["face"] if item["owner"] else None
    video_url = item["uri"]
    owner_name = item["owner"]["name"] if item["owner"] else None
    info = f"title:{title} , owner_name:{owner_name}, video_url:{video_url} ,image_url:{image_url}"
    print(info)
    time.sleep(0.5)
